﻿<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    assembly="JSC.Portal.Core" namespace="JSC.Portal.Entities">

	<class name="PortalPage" table="jsc_page" lazy="false">

		<!-- start Base on every entity -->
		<id name="Id" column="pageid" unsaved-value="-1">
			<generator class="native">
				<param name="sequence">jsc_page_pageid_seq</param>
			</generator>
		</id>

		<property name="Name" column="name" not-null="true"/>
		<property name="Description" column="description"/>
		<!-- end Base on every entity -->

    <property name="Language" column="language"/>
    <property name="FriendlyURL" column="friendlyurl"/>
		<property name="Position" column="position"/>
		<property name="ShowInNavigation" column="showinnavigation"/>
    <property name="ValidFrom" column="validfrom"/>
    <property name="ValidTill" column="validtill"/>
    <property name="MetaKeywords" column="metakeywords"/>
    <property name="MetaDescription" column="metadescription"/>
    <property name="CreatedOn" column="createdtimestamp" type="DateTime"/>
    <property name="ModifiedOn" column="modifiedtimestamp" type="DateTime"/>
    <many-to-one name="CreatedByUser" class="PortalUser" column="createdby" not-null="false" not-found="ignore"/>
    <many-to-one name="ModifiedByUser" class="PortalUser" column="modifiedby" not-null="false" not-found="ignore"/>
		<many-to-one name="Parent" class="PortalPage" column="parentid" not-null="false" not-found="ignore"/>
		<many-to-one name="Template" class="Template" column="templateid" not-null="true" not-found="ignore"/>
    <many-to-one name="PortalSite" class="PortalSite" column="siteid" not-null="false" not-found="ignore"/>

    <bag name="ChildPages" 
         cascade="delete" 
         inverse="true" 
         order-by="position asc" 
         lazy="true">
			<key column="parentid" />
			<one-to-many class="PortalPage" 
                   not-found="ignore"/>
    </bag>
		
		<bag name="Sections"
         table="jsc_section" 
         inverse="true"
         lazy="true"
         order-by="placeholder asc, position asc"
         cascade="all">
			<key column="pageid" />
      <one-to-many class="Section"
                   not-found="ignore" />
		</bag>

    <bag name="PagePermissions"
         cascade="all"
         lazy="true"
         table="jsc_pagerole">
      <key column="pageid" />
      <composite-element class="PortalPagePermission">
        <parent name="Page" />
        <property name="ViewAllowed" column="viewallowed" type="Boolean" />
        <property name="EditAllowed" column="editallowed" type="Boolean" />
        <many-to-one name="Role" class="Role" column="roleid" cascade="none" />
      </composite-element>
    </bag>
    
	</class>
</hibernate-mapping>